//Author: Zhengwei Pu & Lu Xu
// Term project for ECE59500

//If run this game in an operation system based on Chinese, the buttons of the dialog will show Chinese!
//
//But if in English OS, it also works well!
//
//The language of this game is based on your operation system. 

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

/*
 * The Canvas for the game
 */

public class Canvas extends JPanel{
	private int boxWidth,boxHeight;//Width and Height of grid
	//mark the color of grid

	private boolean colorMark[][] = new boolean[Utils.DEFAULT_ROWS][Utils.DEFAULT_COLS];
	//backpround color

	private Color bgColor = Utils.DEFAULT_BG_COLOR;
	//color of snake

	private Color snakeColor = Utils.DEFAULT_SNAKE_COLOR;
	
	public Canvas(){
		adjustSize();	//adjust Size of canvas
		resetCanvas(); //reset the canvas
	}

	//paint method
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		adjustSize();//adjust Size of grid
		for(int i = 0; i < colorMark.length; i++)//painting is based on the markcolor of the grid
			for(int j = 0; j < colorMark[i].length; j++){
				if(colorMark[i][j])
					g.setColor(snakeColor);
				else
					g.setColor(bgColor);
		        g.fill3DRect(j * boxWidth, i * boxHeight, boxWidth, boxHeight, true);
			}
	}

	//reset the canvas,mark the grid as background color
	public void resetCanvas(){
		for (int i = 0; i < colorMark.length; i++)
			for (int j = 0; j < colorMark[i].length; j++)
				colorMark[i][j] = false;
	}

	//adjust Size of grid when the size of canvas is changed
	private void adjustSize(){
		boxWidth = getSize().width / Utils.DEFAULT_COLS;
		boxHeight = getSize().height / Utils.DEFAULT_ROWS;
	}

	//set Spec ColorMark
	public void setSpecColorMark(int row,int col,boolean marked){
		colorMark[row][col] = marked;
	}
}
